package com.muyu.system.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.muyu.common.core.domain.Result;
import com.muyu.common.core.utils.poi.ExcelUtil;
import com.muyu.common.core.web.controller.BaseController;
import com.muyu.common.log.annotation.Log;
import com.muyu.common.log.enums.BusinessType;
import com.muyu.system.domain.DanmoMarketPicture;
import com.muyu.system.service.IDanmoMarketPictureService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;


/**
 * 书画市场图片Controller
 *
 * @author yangle
 * @date 2024-09-08
 */
@RestController
@RequestMapping("/picture")
public class DanmoMarketPictureController extends BaseController
{
    @Autowired
    private IDanmoMarketPictureService danmoMarketPictureService;

    /**
     * 查询书画市场图片列表
     */
//    @RequiresPermissions("system:picture:list")
    @PostMapping("/list")
    public Result list(@RequestBody DanmoMarketPicture danmoMarketPicture)
    {
        PageHelper.startPage(danmoMarketPicture.getPageNum(),danmoMarketPicture.getPageSize());
        List<DanmoMarketPicture> list = danmoMarketPictureService.selectDanmoMarketPictureList(danmoMarketPicture);
        PageInfo<DanmoMarketPicture> danmoMarketPicturePageInfo = new PageInfo<>(list);
        return Result.success(danmoMarketPicturePageInfo);
    }

    /**
     * 导出书画市场图片列表
     */
//    @RequiresPermissions("system:picture:export")
    @Log(title = "书画市场图片", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DanmoMarketPicture danmoMarketPicture)
    {
        List<DanmoMarketPicture> list = danmoMarketPictureService.selectDanmoMarketPictureList(danmoMarketPicture);
        ExcelUtil<DanmoMarketPicture> util = new ExcelUtil<DanmoMarketPicture>(DanmoMarketPicture.class);
        util.exportExcel(response, list, "书画市场图片数据");
    }

    /**
     * 获取书画市场图片详细信息
     */
//    @RequiresPermissions("system:picture:query")
    @GetMapping(value = "/{id}")
    public Result getInfo(@PathVariable("id") Long id)
    {
        return success(danmoMarketPictureService.selectDanmoMarketPictureById(id));
    }

    /**
     * 新增书画市场图片
     */
//    @RequiresPermissions("system:picture:add")
    @Log(title = "书画市场图片", businessType = BusinessType.INSERT)
    @PostMapping
    public Result add(@RequestBody DanmoMarketPicture danmoMarketPicture)
    {
        return toAjax(danmoMarketPictureService.insertDanmoMarketPicture(danmoMarketPicture));
    }

    /**
     * 修改书画市场图片
     */
//    @RequiresPermissions("system:picture:edit")
    @Log(title = "书画市场图片", businessType = BusinessType.UPDATE)
    @PutMapping
    public Result edit(@RequestBody DanmoMarketPicture danmoMarketPicture)
    {
        return toAjax(danmoMarketPictureService.updateDanmoMarketPicture(danmoMarketPicture));
    }

    /**
     * 删除书画市场图片
     */
//    @RequiresPermissions("system:picture:remove")
    @Log(title = "书画市场图片", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public Result remove(@PathVariable Long[] ids)
    {
        return toAjax(danmoMarketPictureService.deleteDanmoMarketPictureByIds(ids));
    }
}
